



class Solution:
    def swapPairs(self, head):

        if not head or not head.next:
            return head

        dummpy = ListNode(0, next=head)

        stack = []
        cur = head
        ans = dummpy

        # 一对的
        while cur and cur.next:

            stack.append(cur)
            stack.append(cur.next)

            cur = cur.next.next

            ans.next = stack.pop()
            ans.next.next = stack.pop()

            ans = ans.next.next

        # 说明是奇数
        if cur:

            ans.next = cur
        
        else:
            ans.next = None

        return dummpy.next
